<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <h:head>
        <title>#{projectsBean.selectedProject.id}</title>
    </h:head>
    <h:body>
        #{resurceBean.filteredResource=null}
        <f:view contracts="main">
            <ui:composition template="/template.xhtml">
                <ui:define name="content">
                    <h:form prependId="false" id="form">
                        <p:growl id="messages" showDetail="true" /> 
                        <p:tabView effect="slide" effectDuration="slow" id="tabs" value="#{departmentsController.departs}" var="dept" dynamic="true" cache="false">

                            <p:tab  title="#{dept.name}" >

                                <p:commandButton icon="ui-icon-circle-plus" update="tree" action="#{resurceBean.expandOrCollapse(dept, true)}" immediate="true"/>
                                <p:commandButton icon="ui-icon-circle-minus" update="tree" action="#{resurceBean.expandOrCollapse(dept, false)}" immediate="true"/>

                                <p:tree animate="true" id="tree" value="#{resurceBean.getTree(dept)}" cache="false"  var="resTree" widgetVar="myTree" selectionMode="single" orientation="horizontal" selection="#{resurceBean.selectedNode}">
                                    <p:ajax event="select" listener="#{resurceBean.onNodeSelect}" update=":form:tabs:resTable, :form:messages"/>
                                    <p:treeNode icon="ui-icon-image" >
                                        <h:outputText value="#{resTree}"/>
                                    </p:treeNode>

                                </p:tree>
                                <p:dock  id="resourceDock" widgetVar="dock" position="top" >
                                    <p:menuitem icon="unfiltered/images/pdf.png" title="Add PDF" oncomplete="PF('uploadDiag').show();">
                                        <f:setPropertyActionListener value="pdf"   
                                                                     target="#{resurceBean.fileType}" /> 
                                        <f:setPropertyActionListener value="/(\.|\/)(pdf)$/"   
                                                                     target="#{resurceBean.allowedTypes}" /> 
                                        <f:setPropertyActionListener value="#{dept.toString()}" target="#{resurceBean.deptartment}"/>
                                    </p:menuitem>
                                    <p:menuitem icon="unfiltered/images/image.png" title="Add image" oncomplete="PF('uploadDiag').show();">
                                        <f:setPropertyActionListener value="image"   
                                                                     target="#{resurceBean.fileType}" /> 
                                        <f:setPropertyActionListener value="/(\.|\/)(gif|jpe?g|png)$/"   
                                                                     target="#{resurceBean.allowedTypes}" /> 
                                        <f:setPropertyActionListener value="#{dept.toString()}" target="#{resurceBean.deptartment}"/>
                                    </p:menuitem>
                                    <p:menuitem icon="unfiltered/images/office.png" title="Add MS Doc" oncomplete="PF('uploadDiag').show();">
                                        <f:setPropertyActionListener value="docs"   
                                                                     target="#{resurceBean.fileType}" /> 
                                        <f:setPropertyActionListener value="/(\.|\/)(doc?|xls?)$/"   
                                                                     target="#{resurceBean.allowedTypes}" /> 
                                        <f:setPropertyActionListener value="#{dept.toString()}" target="#{resurceBean.deptartment}"/>
                                    </p:menuitem>
                                    <p:menuitem icon="unfiltered/images/cad.png" title="Add cad doc" oncomplete="PF('uploadDiag').show();">
                                        <f:setPropertyActionListener value="cad"   
                                                                     target="#{resurceBean.fileType}" /> 
                                        <f:setPropertyActionListener value="/(\.|\/)(cad)$/"   
                                                                     target="#{resurceBean.allowedTypes}" /> 
                                        <f:setPropertyActionListener value="#{dept.toString()}" target="#{resurceBean.deptartment}"/>
                                    </p:menuitem>
                                    <p:menuitem icon="unfiltered/images/prima.png" title="Add Primavera" oncomplete="PF('uploadDiag').show();">
                                        <f:setPropertyActionListener value="prima"   
                                                                     target="#{resurceBean.fileType}" /> 
                                        <f:setPropertyActionListener value="/(\.|\/)(doc?|xls?)$/"   
                                                                     target="#{resurceBean.allowedTypes}" /> 
                                        <f:setPropertyActionListener value="#{dept.toString()}" target="#{resurceBean.deptartment}"/>
                                    </p:menuitem>
                                    <p:menuitem icon="unfiltered/images/Revit.png" title="Add rivet" oncomplete="PF('uploadDiag').show();">
                                        <f:setPropertyActionListener value="revit"   
                                                                     target="#{resurceBean.fileType}" /> 
                                        <f:setPropertyActionListener value="/(\.|\/)(doc?|xls?)$/"   
                                                                     target="#{resurceBean.allowedTypes}" /> 
                                        <f:setPropertyActionListener value="#{dept.toString()}" target="#{resurceBean.deptartment}"/>
                                    </p:menuitem>
                                </p:dock>

                                <p:dataTable  id="resTable" var="res" value="#{resurceBean.getResources(dept)}" 
                                              paginator="true" rows="100" 
                                              paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                                              rowsPerPageTemplate="3,25,50,100,250,500"
                                              filteredValue="#{resurceBean.filteredResource}"
                                              > 
                                    <p:column headerText="Reource Name" sortBy="name" filterBy="name" filterMatchMode="contains"> 
                                        <h:outputText value="#{res.name}" /> 
                                    </p:column>
                                    <p:column headerText="Resource author" sortBy="#{res.author}}" filterBy="#{res.author}" filterMatchMode="contains"> 
                                        <h:outputText value="#{res.author}" /> 
                                    </p:column>
                                    <p:column  filterBy="#{res.section}"   
                                               headerText="Section"  

                                               filterMatchMode="exact"
                                               >  
                                        <h:outputText value="#{res.section}" style="width: auto"/>  
                                    </p:column>
                                    <p:column  filterBy="#{res.creationDate}"   
                                               headerText="Created On"  
                                               filterMatchMode="contains"
                                               sortBy="#{res.creationDate}"
                                               >  
                                        <h:outputText value="#{res.creationDate}" style="width: auto"/>  
                                    </p:column>
                                    <p:column    
                                        headerText="Resource Type"  
                                        filterBy="#{res.type}" 
                                        filterOptions="#{resurceBean.sectionOptions}"  
                                        filterMatchMode="exact"
                                        >  
                                        <h:outputText value="#{res.type}" style="width: auto"/>  
                                    </p:column> 

                                    <p:column    headerText="Details"  rendered="#{login.current.canWrite(dept)}">
                                        <div class="center">
                                        <p:commandLink update="resTable,:form:carDetail" id="detail" type="button" oncomplete="PF('viewer').show()"  title="View Detail" immediate="true">   
                                            <p:graphicImage value="unfiltered/images/view2.png" width="25" height="30" style="margin:0 auto;"/>

                                            <f:setPropertyActionListener value="#{res}"   
                                                                         target="#{resurceBean.selectedResource}" />  
                                        </p:commandLink>  
                                            </div>
                                        <div class="center">
                                            <p:commandButton process="resTable" icon="ui-icon-trash" id="delete" action="#{resurceBean.deleteResource}"  title="Delete" update="resTable">   

                                                <f:setPropertyActionListener value="#{res}"   
                                                                             target="#{resurceBean.selectedResource}" /> 
                                            </p:commandButton> 
                                        </div>
                                    </p:column> 

                                </p:dataTable> 







                            </p:tab>
                        </p:tabView>
                        <p:dialog widgetVar="viewer" header="Vewi Detail"  dynamic="true" id="viewerDiag" style="width: auto;height: 350px" position="left,top" resizable="false">
                            <p:outputPanel id="carDetail" style="text-align:center;" rendered="#{ resurceBean.selectedResource.resourceType eq 'file_resource'}">
                                <p:panelGrid columns="1">
                                    <f:facet name="header">#{resurceBean.selectedResource.name}</f:facet>

                                    <p:media value="#{resurceBean.getMedia('application/pdf')}"  player="pdf" width="750" height="400" rendered="#{resurceBean.selectedResource.type eq 'pdf'}">
                                        <f:param name="fileName" value="#{resurceBean.selectedResource.path}" />
                                        <f:param name="fileType" value="#{resurceBean.selectedResource.type}" />
                                    </p:media>
                                    <p:outputPanel style="max-width: 800px;max-height: 500px; overflow: auto " rendered="#{resurceBean.selectedResource.type eq 'image'}">
                                    <p:graphicImage value="#{resurceBean.getMedia('image')}" title="image"  cache="false"  >
                                        <f:param name="fileName" value="#{resurceBean.selectedResource.path}" />
                                        <f:param name="fileType" value="#{resurceBean.selectedResource.type}" />

                                    </p:graphicImage>
                                        </p:outputPanel>
                                    <f:facet name="footer">
                                    <p:commandButton value="Download" ajax="false" icon="ui-icon-arrowthichk-s">
                                        <f:param name="fileName" value="#{resurceBean.selectedResource.path}" />
                                        <f:param name="fileType" value="#{resurceBean.selectedResource.type}" />
                                        <p:fileDownload value="#{resurceBean.getMedia('application/pdf')}"/>
                                    </p:commandButton>
                                    <p:commandButton value="Cancel"  icon="ui-icon-arrowreturnthick-1-w" oncomplete="PF('viewer').hide()"/>
                                    </f:facet>
                                </p:panelGrid>
                            </p:outputPanel>
                        </p:dialog>
                        <p:dialog dynamic="true" closable="false" header="Upload Resource" hideEffect="fade" widgetVar="uploadDiag" id="diag" position="top">
                            <p:panelGrid columns="2" >
                                
                                <p:outputLabel for="file" value="File"/>
                                <p:fileUpload required="true" style="height: 200px;overflow: auto" id="file"  dragDropSupport="true" fileUploadListener="#{resurceBean.setUploadedFile}"  multiple="true"/>
                                <f:facet name="footer">
                                    <p:commandButton   update="form" value="Create" action="#{resurceBean.saveFileResource()}" icon="ui-icon-arrowreturnthick-1-w" oncomplete="PF('uploadDiag').hide()"/>
                                    <p:commandButton value="Cancel" action="#{resurceBean.clearList()}" icon="ui-icon-arrowreturnthick-1-w" oncomplete="PF('uploadDiag').hide()"/>
                                </f:facet>
                            </p:panelGrid>
                        </p:dialog>
                        <p:dialog widgetVar="genSiteDiag" dynamic="true" style="width: auto;height: auto" header="General Site">
                            <ui:include src="dialogs/generalSiteDialog.xhtml" ></ui:include>
                        </p:dialog>
                    </h:form>
                </ui:define>

            </ui:composition>
        </f:view>
    </h:body>
</html>

